package alpha.com.google.code.mechanic.janitor.controller;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import alpha.com.google.code.mechanic.janitor.controller.MechanicTaskSource;

import com.google.eclipse.mechanic.tests.internal.RunAsPluginTest;

@RunAsPluginTest
public class MechanicTaskSourceTest {
  
  private MechanicTaskSource taskSource;

  @Before
  public void setUp() throws Exception {
    taskSource = new MechanicTaskSource();
  }

  @After
  public void tearDown() throws Exception {
  }

  @Test
  public void testRemoveAllCtxDirFromTaskSrc() {
    
    if (taskSource.addDirectoryToTaskSrc("test/.eclipse.eclipse/"
        + "mechanic/Contexts/Source 2")) {
      taskSource.removeAllCtxDirFromTaskSrc();
      
      assertFalse(taskSource.getCurTaskSources().contains("test/.eclipse/"
        + "mechanic/Contexts/Source 2"));
    } else {
      fail("Couldn't add directory to task sources.");
    }
    
  }

  @Test
  public void testAddDirectoryToTaskSrc() {
    assertTrue(taskSource.addDirectoryToTaskSrc("test/.eclipse/"
        + "mechanic/Contexts/Source 1"));
    assertFalse(taskSource.addDirectoryToTaskSrc("test/.eclipse/"
        + "mechanic/Contexts/Source 1"));
  }

  @Test
  public void testHasSameLocation() {
        
    taskSource.addDirectoryToTaskSrc("Contexts/Context 3");
    String dirs = taskSource.getCurTaskSources();
    
    assertTrue(taskSource.hasSameLocation(dirs, "Contexts/Context 3"));
    assertFalse(taskSource.hasSameLocation(dirs, "Contexts/Context 4"));
  }

}
